#发送请求
import requests
from lxml import etree
#发送给谁
url='https://www.banjiashi.com/xiaoshuo/91881/27801562.html'
while True:
    #伪装自己
    headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0'}
    #响应信息
    resp=requests.get(url,headers=headers)
    resp.encoding="utf-8"
    #第一章内容(用etree把html转成文本)
    e=etree.HTML(resp.text)
    info='\n'.join(e.xpath('//div/p[position()>3][position()<last()]/text()'))
    title=e.xpath('//h2/text()')[0]
    url=f'https://www.banjiashi.com/{e.xpath("//div[@class='read_btn']/a[4]/@href")[0]}'
    #保存
    with open("奇诡航海.txt","a+",encoding="utf-8") as f:
        f.write(title+'\n\n'+info+'\n\n')
    if url=='//*[@id="content"]/div[2]/a[4]/@href':
        break